﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Data;

public partial class KMrpt2 : BaseRptPage
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.Load += new System.EventHandler(Page_Load);
    } 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //bindshop("");
            this.txtsdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            this.txtedate.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        GvBind();
    }
    protected void bindshop(string shopname)
    {
        this.chkblist.Items.Clear();
        string str = "";
        if (shopname != "")
        {
            str += " and shopname like '%" + shopname + "%'";
        }
        DataSet ds = db.DM_GetDateSet("select * from Bas_Shop where 1=1 " + str + " order by shopname");
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            ListItem item = new ListItem();
            item.Text = dr["shopname"].ToString();
            item.Value = dr["shopid"].ToString();
            this.chkblist.Items.Add(item);
        }
    }
    protected void GvBind()
    {
        string val = " ";
        if (this.business.Text.Trim() != "")
        {
            val += "(";
            string[] list = business.Text.Split(';');
            foreach (string s in list)
            {
                val += "''" + s + "'',";
            }
            val = val.TrimEnd(',');
            val += ")";
        }
        int zt = 0;
        if (this.CheckBox1.Checked == true){
            zt= 1;
        }else{
            zt = 0;
        }
        this.GridView1.DataSource = db.DM_GetDateSet("exec KM_ShopWeekStructure_RPT '"
            +this.txtsdate.Text+"','"+this.txtedate.Text+"','','"+txtbigarea.Text+"','"+txtarea.Text+"','"+val+"','',"+zt);
        this.GridView1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        GridView1.AllowPaging = false;
        GvBind();
        GridViewToExcel(this.GridView1, "application/ms-excel", this.Title + ".xls");
        GridView1.AllowPaging = true;
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        GvBind();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        bindshop(this.txtshopname.Text);
    }
}